use diesel::prelude::*;

use crate::database::schema;

#[derive(Queryable, Selectable)]
#[diesel(table_name = schema::user)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct User {
    pub id: i32,
    pub username: String,
    pub password: String,
    pub tid: i32,
}

#[derive(Insertable, AsChangeset)]
#[diesel(table_name = schema::user)]
pub struct NewUser<'a> {
    pub username: &'a str,
    pub password: &'a str,
    pub tid: i32,
}

impl<'a> From<&'a User> for NewUser<'a> {
    fn from(user: &'a User) -> Self {
        NewUser {
            username: &user.username,
            password: &user.password,
            tid: user.tid,
        }
    }
}
